<?php
namespace Home\Controller;
use Think\Controller;
class QuotationController extends Controller {
    //报价单控制器
    //首页
    public function index($page=1,$sort=''){
        if(session('member_id')){
            $member_id=session('member_id');
            $member_name=session('member_name');
        }
        //echo $member_id;exit;
        $data['title']='报价单_找金银网';
        $data['active']='quotation';
        $Model=D("Quotation");
        //参数  页数
        if(intval($page)==0){
            $page=1;
        }else{
            $page=intval($page);
        }
        $perpage=10;
        $Model->page=$page;
        $Model->perpage=$perpage;
        $quotation_list=$Model->get_quotation_list();
        //print_r($quotation_list);exit;
        $quotation_total=$Model->get_quotation_total();
        //echo $quotation_total;exit;
        $page_total=ceil($quotation_total/$perpage);
        //echo $page_total;exit;
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['perpage']=$perpage;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['quotation_total']=$quotation_total;
        $pager['page_total']=$page_total;
        //$cat_list=$Model->get_cat_list();
        $this->assign("data",$data);
        $this->assign("quotation_list", $quotation_list);
        //$this->assign("cat_list", $cat_list);
        $this->assign("pager",$pager);
        $this->assign("member_id", $member_id);
        $this->assign("member_name", $member_name);
        $this->display();
    }
    public function quotation_view($id='',$page=1){
        if(session('member_id')){
            $member_id=session('member_id');
            $member_name=session('member_name');
        }
        $data['title']='查看资源单_找金银网';
        if(intval($id)==0){
            $quotation_id=1;
        }else{
            $quotation_id=intval($id);
        }
        if(intval($page)==0){
            $page=1;
        }else{
            $page=intval($page);
        }
        $Model=D("quotation");
        $Member=D("Member");  //会员
        $Model->quotation_id=$quotation_id;
        $quotation_info=$Model->get_quotation_info();
        $excel_file=$quotation_info['quotation_file'];
        $excel_file=mb_strcut($excel_file,1);
        //读取excel
        vendor('Excelreader.Reader');
        vendor('Excelreader.Oleread');
        $Reader=new \Spreadsheet_Excel_Reader(); //实例化
        $Reader->setOutputEncoding('utf-8');      //编码
        $Reader->read( $excel_file);            //读取的文件
        $excel_data_list=$Reader->sheets[0]['cells'];
        $this->assign("data", $data);
        $this->assign("member_id", $member_id);
        $this->assign("member_name", $member_name);
        $this->assign("quotation_info", $quotation_info);
        $this->assign("excel_data_list", $excel_data_list);
        $this->display();
    }

}